package com.newbie.iSee;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class RecentButton extends Button {
	private Context _context;
	//private int _type;
	
	String[] _text; // on the button
	private String _urlPic;
	private event _event;
	private String _type  = "";
	
	public RecentButton(Context context/* jimmy wang */) {
		super(context);
		
		/* you can write something here */
	}
	
	public RecentButton(Context context, event event) {
		super(context);
		
		_context = context;
		_event = event;
		
		//Log.d("event",_event.);
		if(_event == null)
			return;
		
		_type = _event.event_type;
				
		if(_type.equals("post_comment")){
			String res=_event.uname;
			res+= " said to ";
			res+= _event.Pownername;
			res+= " ...\n";
			if(isRecord(_event.msg))
				res += "listen to me!!";
			else
				res+= _event.msg;
			this.setText(res);;
			Log.d("text",res);

		}
		else if(_type.equals("upload_photo")){
			
			String res=_event.uname;
			res+= " uploaded a photo ";
			this.setText(res);	
			Log.d("text",res);
		}
		else{
			Log.d("text", "here here "+_type+"*");
		}

		setImage();
		setOnClickListener(actionClick());
	}
	
	private boolean isRecord(String msg) {
		String[] toks = msg.split("\\ ");
		if(toks.length != 2)
			return false;
		return toks[0].equals("[click]");
	}

	
	private void setImage() {
		Activity activity = (Activity) _context;
		setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.plurk));
	}
	
    private View.OnClickListener actionClick() {
    	View.OnClickListener action = new View.OnClickListener() {
    		public void onClick(View v) {
    			
    			//post_comment, upload_album, upload_photo

    			String pid = _event.tid;
    			Intent change = new Intent(v.getContext(), PhotoPage.class);
    			change.putExtra("pid", pid);
    			Activity activity = (Activity) _context;
    			activity.startActivityForResult(change, 0);
            }
    	};
    	return action;
    }
    

    
    
    
    
}
